fix: update functional components in hmr.reload() #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An SFC functional component that does not use
<template functional>
will go through__VUE_HMR_RUNTIME__.reload()
instead of.rerender()
, because the plugin can't detect thefunctional template attr
to inject its_rerender_only
marker.After updating the component's options, the reload function will still try to reload it by updating its parent via
$vnode.context
. This causes two issues:instance
already points to the component's (stateful) parent. In turn, the functional component's grandparent is updated, which does not cause the functional component down the tree to rerender. (unless props changed) So the update does not appear on the screen until maybe later some other condition causes a rerender:instance
will point to the root. The runtime notices that the instance has no parent context (which would be the child's grandparent) and issues a warning about unsupported root HMR instead of updating the child:To fix this, this PR makes
__VUE_HMR_RUNTIME__.reload
call.$forceUpdate()
on the instance itself instead of on the parent context if the reloaded component is functional.